package com.txzhang.core;

import java.util.concurrent.ConcurrentHashMap;

/**
 * @author txzhang
 * @date 2021/1/5 13:50
 */
public class BeanRegister {

    private static ConcurrentHashMap<String, Object> IOC_DATA = new ConcurrentHashMap<>();

    public static void add(Class clazz, Object beanInstance) {
        String beanName = clazz.getName() + "$$";
        Object o = IOC_DATA.get(beanName);
        if (o == null) {
            IOC_DATA.put(beanName, beanInstance);
        } else {
            System.out.println("this bean has already register" + o.getClass().getName());
        }
    }

    public static Object getBean(String beanName) {
        return IOC_DATA.get(beanName);
    }

    public static ConcurrentHashMap<String, Object> getIocData() {
        return IOC_DATA;
    }
}
